(function() {
    //获取首页nav数据 并渲染到页面
    fetch('http://chst.vip:1234/api/getindexmenu').then(body => body.json()).then(res => {
        let result = res.result;
        // console.log(result);
        let navStr = '';
        result.forEach(item => {
            navStr += `
            <li date-index="${item.indexmenuId}">
                <a href="${item.titlehref}">
                    <i></i>
                    <h4>${item.name}</h4>
                </a>
            </li>
            `
        });
        $('.navlis').html($(navStr));
        //点击更多  展开第三行
        let isShow = true;
        $('.navlis > li').eq(7).on('click', function() {
            if (isShow) {
                $(this).parent().stop().animate({ height: '2.55rem' }, 500);
                isShow = false;
            } else {
                $(this).parent().stop().animate({ height: '1.68rem' }, 500);
                isShow = true;
            }
        })
    });
    //获取折扣列表数据  并渲染
    fetch('http://chst.vip:1234/api/getmoneyctrl').then(body => body.json()).then(res => {
        let result = res.result;
        console.log(result);
        let discStr = '';
        result.forEach(item => {
            discStr += `
            <li date-productId="${item.productId}">
                    <a href="javascript:;">
                        <div class="imgico">
                            ${item.productImgSm}
                        </div>
                        <div class="info">
                            <h3>${item.productName}</h3>
                            <span class="price">¥ ${item.productPinkage}</span>
                            <div class="desc">
                                <span class="times">${item.productFrom} | ${item.productTime}</span>
                                <div class="review">
                                    <i></i>
                                    <span>${item.productComCount}</span>
                                </div>
                            </div>
                        </div>
                    </a>
                </li>
            `
        });
        $('.discBody > ul').html($(discStr));
    });
    $('.discBody').on('click', 'li', function() {

        location.href = '../html/discountXQ.html?productid=' + $(this).attr('date-productId')
    })
})()

$('.gotop').click(function() {
    //设置scrollTop
    $('html,body').animate({
        scrollTop: 0
    }, 500)
})